import  xlrd
import xlwt

#写excel

book = xlwt.Workbook()
sheet =book.add_sheet("sheet1")
sheet.write(0,0,"id") #第0行第0列
sheet.write(0,1,"name") #第0行第2列
sheet.write(1,0,"1")
sheet.write(1,1,"wxy")

book.save("student.xls")
#微软的office 结尾用.xlsx打不开
#用wps xls和xlsx都可以打开


#读excel
book =xlrd.open_workbook("student.xls")
sheet = book.sheet_by_index(0)
sheet =book.sheet_by_name("sheet1")
print(sheet.cell(0,0).value) #指定单元格
print(sheet.row_values(0)) #获取某一行的数据
print(sheet.col_values(0))#获取某一列的数据
print(sheet.nrows) #共有多少行
print(sheet.ncols) #总共有多少列


# 修改excel
from xlutils import  copy

book =xlrd.open_workbook("student.xls")
new_book=copy.copy(book)
sheet=new_book.get_sheet(0)
sheet.write(0,0,"编码")
new_book.save("student.xls")